<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;
use GuzzleHttp\Client as GuzzleClient;


class CashGender extends AbstractTool
{
    protected function script()
    {
        return <<<EOT

EOT;
    }

    public function render()
    {
        Admin::script($this->script());

        $url = env('OTHER_API').'/get_cash';
        $params = [
            'query' => ['sign' => env('SIGN')]
        ];
        $response = $this->guzzle($url, $params);
        $cash = json_decode($response->getBody()->getContents(), true)['cash'];

        return view('admin.tools.cash', compact('cash'));
    }

    protected function guzzle($url, $params)
    {
        $client = new GuzzleClient([
            // 超时
            'timeout' => 5.0,
        ]);
        return $client->request('GET', $url, $params);
    }
}